<?php
class account extends adminController {
    public $_indexView = "admin/account/index";
    public $_listView = "admin/account/list";
    public $_addView = "admin/account/add";
    public $_editView = "admin/account/edit";
    public $_loginView = "admin/account/login";
    
	public function __construct() {
		parent::__construct ();
	}
	
    public function loadView($temp) {
        if (!isset($temp["data"]))
            $temp["data"] = '';
        $this->load->view("admin/index", $temp);
    }
    
    public function index() {
        $temp["template"] = $this->_listView;
        $temp["data"] = $this->accountModel->get();
        $this->loadView($temp);
    }
    
    public function add() {
        $temp["template"] = $this->_addView;
        if(!$this->isPost()) {
            $temp["roles"] = $this->roleModel->get();
            $this->loadView($temp);
            return;   
        }
        $data = $this->input->post();
        $data['passwordd'] = md5($data['passwordd']);
        $this->accountModel->insert($data);
        $this->index();
    }
    
    public function edit($id) {
        $temp["template"] = $this->_editView;
        if(!$this->isPost()) {
            $temp["data"] = $this->accountModel->read($id);
            $temp["roles"] = $this->roleModel->get();
            $this->loadView($temp);
            return;   
        }
        $this->accountModel->update($this->input->post(), array('id' => $id));
        redirect(base_url().$this->_indexView);
    }
    
    public function delete($id) {
        $this->accountModel->delete($id);
        redirect(base_url().$this->_indexView);
    }
}
?>